package org.apache.ibatis.test20200320;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author: ShipTang
 * @Description:
 * @Date: 2021/3/20 16:51
 */
public class RouteProxy implements InvocationHandler {

    private Logger logger= LoggerFactory.getLogger(RouteProxy.class);

    @Override
    public Object invoke(Object proxy, Method method, Object[] args)
            throws Throwable {
        logger.info("进入代理方法{}",method.getName());
        Thread.sleep(2000);
        logger.info("执行完成代理方法{}",method.getName());
        return null;
    }

    @SuppressWarnings("unchecked")
    public   static <T> T getProxy(Class<T> interfaceClass){
        return (T) Proxy.newProxyInstance(RouteProxy.class.getClassLoader(),
                new Class[]{interfaceClass}, new RouteProxy());
    }
}
